/*  ----------------------------------------------------------------------------
 *  Arello Mobile
 *  Fast 3d Engine
 *  ----------------------------------------------------------------------------
 * Except where otherwise noted, this work is licensed under
 * http://creativecommons.org/licenses/by/3.0
 */

#include <lib3d/hard/Hardware.h>
#include <xml/Stream.h>
#include <Converter.h>
#include <safe_new.h>

#include "Billboard.h"

namespace liba
{
namespace lib3d
{
namespace node
{

const Atom Billboard::node_name( "Billboard" );
const Atom Billboard::restricted_name( "Restricted" );

Billboard::Billboard( const Atom & name, Node * parent )
:	Node( name, parent ),
	restricted( false )
{
	node_type = node_name;
	this->RegisterProperty( restricted_name, &this->restricted );
}

Billboard::~Billboard()
{}

Billboard * Billboard::Clone()
{
	return new Billboard(*this);
}

bool Billboard::on_attribute( xml::Provider * prov, const std::string & name, const std::string & value )
{
	if ( name == "Restricted" )
	{
		bool restricted;
		bool res = converter::convert( value, &restricted );
		if (res)
			this->restricted = restricted;
		return res;
	}
	return Node::on_attribute( prov, name, value );
}

void Billboard::RenderToList( hard::Hardware * hardware, hard::RenderList * render_list )
{
	Matrix newTotal = render_list->camera_world;
	Vector position      = GetGlobalPosition();
	newTotal.rc(0,3) = position.x;
	newTotal.rc(1,3) = position.y;
	newTotal.rc(2,3) = position.z;
	SetGlobalMatrix(newTotal);
	
	return Node::RenderToList( hardware, render_list );
}


} // namespace node
} // namespace lib3d
} // namespace liba


